#ifndef __STORMWIDGET_STORMWIDGET_UILIBRARY_CACTIVEXCTRL_ACTIVEXCTRL_H
#define __STORMWIDGET_STORMWIDGET_UILIBRARY_CACTIVEXCTRL_ACTIVEXCTRL_H

class CActiveXWnd;
class CActiveXUI;

class CActiveXCtrl :
	public IOleClientSite,
	public IOleInPlaceSiteWindowless,
	public IOleControlSite,
	public IObjectWithSite,
	public IOleContainer
{
	friend CActiveXUI;
	friend CActiveXWnd;
public:
	CActiveXCtrl(void);
	virtual ~CActiveXCtrl(void);

	// IUnknown
	STDMETHOD_(ULONG,AddRef)();
	STDMETHOD_(ULONG,Release)();
	STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppvObject);

	// IObjectWithSite
	STDMETHOD(SetSite)(IUnknown *pUnkSite);
	STDMETHOD(GetSite)(REFIID riid, LPVOID* ppvSite);

	// IOleClientSite
	STDMETHOD(SaveObject)(void);       
	STDMETHOD(GetMoniker)(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker** ppmk);
	STDMETHOD(GetContainer)(IOleContainer** ppContainer);        
	STDMETHOD(ShowObject)(void);        
	STDMETHOD(OnShowWindow)(BOOL fShow);        
	STDMETHOD(RequestNewObjectLayout)(void);

	// IOleInPlaceSiteWindowless
	STDMETHOD(CanWindowlessActivate)(void);
	STDMETHOD(GetCapture)(void);
	STDMETHOD(SetCapture)(BOOL fCapture);
	STDMETHOD(GetFocus)(void);
	STDMETHOD(SetFocus)(BOOL fFocus);
	STDMETHOD(GetDC)(LPCRECT pRect, DWORD grfFlags, HDC* phDC);
	STDMETHOD(ReleaseDC)(HDC hDC);
	STDMETHOD(InvalidateRect)(LPCRECT pRect, BOOL fErase);
	STDMETHOD(InvalidateRgn)(HRGN hRGN, BOOL fErase);
	STDMETHOD(ScrollRect)(INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip);
	STDMETHOD(AdjustRect)(LPRECT prc);
	STDMETHOD(OnDefWindowMessage)(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult);

	// IOleInPlaceSiteEx
	STDMETHOD(OnInPlaceActivateEx)(BOOL *pfNoRedraw, DWORD dwFlags);        
	STDMETHOD(OnInPlaceDeactivateEx)(BOOL fNoRedraw);       
	STDMETHOD(RequestUIActivate)(void);

	// IOleInPlaceSite
	STDMETHOD(CanInPlaceActivate)(void);       
	STDMETHOD(OnInPlaceActivate)(void);        
	STDMETHOD(OnUIActivate)(void);
	STDMETHOD(GetWindowContext)(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo);
	STDMETHOD(Scroll)(SIZE scrollExtant);
	STDMETHOD(OnUIDeactivate)(BOOL fUndoable);
	STDMETHOD(OnInPlaceDeactivate)(void);
	STDMETHOD(DiscardUndoState)( void);
	STDMETHOD(DeactivateAndUndo)( void);
	STDMETHOD(OnPosRectChange)(LPCRECT lprcPosRect);

	// IOleWindow
	STDMETHOD(GetWindow)(HWND* phwnd);
	STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode);

	// IOleControlSite
	STDMETHOD(OnControlInfoChanged)(void);      
	STDMETHOD(LockInPlaceActive)(BOOL fLock);       
	STDMETHOD(GetExtendedControl)(IDispatch** ppDisp);        
	STDMETHOD(TransformCoords)(POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags);       
	STDMETHOD(TranslateAccelerator)(MSG* pMsg, DWORD grfModifiers);
	STDMETHOD(OnFocus)(BOOL fGotFocus);
	STDMETHOD(ShowPropertyFrame)(void);

	// IOleContainer
	STDMETHOD(EnumObjects)(DWORD grfFlags, IEnumUnknown** ppenum);
	STDMETHOD(LockContainer)(BOOL fLock);

	// IParseDisplayName
	STDMETHOD(ParseDisplayName)(IBindCtx* pbc, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);

protected:
	HRESULT CreateActiveXWnd();

protected:
	LONG m_dwRef;
	CActiveXUI* m_pOwner;
	CActiveXWnd* m_pWindow;
	IUnknown* m_pUnkSite;
	IViewObject* m_pViewObject;
	IOleInPlaceObjectWindowless* m_pInPlaceObject;
	bool m_bLocked;
	bool m_bFocused;
	bool m_bCaptured;
	bool m_bUIActivated;
	bool m_bInPlaceActive;
	bool m_bWindowless;
};
#endif //__STORMWIDGET_STORMWIDGET_UILIBRARY_CACTIVEXCTRL_ACTIVEXCTRL_H